﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;
namespace EC21_EDiamond
{
    public partial class QuanLyTinh : System.Web.UI.Page
    {
        TinhBUS tinhbus = new TinhBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDanhSachTinhGv();
            }
        }
        void LoadDanhSachTinhGv()
        {
            grwDanhSachTinh.DataSource = tinhbus.LoadDanhSachTinhGv();
            grwDanhSachTinh.DataBind();
        }
        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (matinh == 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Chưa Chọn tỉnh!');", true);
                return;
            }
            TinhDTO tinh = new TinhDTO();
            tinh.MaTinh  = matinh;
            tinh.TenTinh  = txtTenTinh.Text;
            tinh.Phivanchuyen = int.Parse(txtPhiVanChuyen.Text);
            if (tinhbus.CapNhatTinh(tinh) != 0)
            {
                LoadDanhSachTinhGv();
                txtTenTinh .Text ="";
                txtPhiVanChuyen .Text ="";
                matinh= 0;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Cập Nhật Thành Công!');", true);             
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Cập Nhật Thất Bại!');", true);
            }
        }
        static int matinh = 0;
        protected void grwDanhSachTinh_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            matinh = int.Parse(grwDanhSachTinh .Rows[e.NewSelectedIndex].Cells[1].Text);
            txtTenTinh .Text = grwDanhSachTinh.Rows[e.NewSelectedIndex].Cells[2].Text;
            txtPhiVanChuyen.Text = grwDanhSachTinh.Rows[e.NewSelectedIndex].Cells[3].Text;
           // txtTenUser.Text = HttpUtility.HtmlDecode(grwDanhSachKhachHang.Rows[e.NewSelectedIndex].Cells[2].Text);
           // txtDiaChi.Text = HttpUtility.HtmlDecode(grwDanhSachKhachHang.Rows[e.NewSelectedIndex].Cells[4].Text); 
        }

    }
}